<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
<%@taglib prefix="rich" uri="http://richfaces.org/rich"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%--
    This file is an entry point for JavaServer Faces application.
--%>
<f:view>
    <html>
        <head>
            <link rel="stylesheet" type="text/css" href="/NamibiaMedicalControl/style.css" title="Variant Stream" media="screen,projection" >
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title><h:outputText value="Visualizza richiami"/></title>
        </head>
        <body>

            <div id="wrapper">
                <div id="logo">
                    <h1>Namibia medical control</h1>
                    <p><h:outputText value="#{msg.sottotitolo}"/></p>
                </div>
                <hr>
                <!-- end #logo -->
                <div id="header">
                    <div id="menu">
                        <ul>
                            <li><a href="/NamibiaMedicalControl/faces/home.jsp" class="first" >Home</a></li>           
                        </ul>
                    </div>
                    <!-- end #menu -->
                    <div id="search">
                        <div id="search-text">
                            <h:panelGroup rendered="#{loginBean.subview != null}">
                                <jsp:include page="${loginBean.subview}" />
                            </h:panelGroup>
                        </div>
                    </div>
                    <!-- end #search -->
                </div>
                <!-- end #header -->
                <!-- end #header-wrapper -->
                <div id="page">
                    <div id="page-bgtop">
                        <div id="content">
                            <div class="post">
                                <h2 class="title"><h:outputText value="Visualizza richiami"/></h2>
                                <div class="entry">
                                    <h3><h:outputText value="Al momento non ci sono richiami in sospeso" rendered="#{(visiteBean.listaRichiami()==null)}"/></h3>
                                    <h:form id="form" rendered="#{(visiteBean.listaRichiami()!=null)}">
                                        <a4j:keepAlive beanName="visiteBean"/>
                                        <rich:dataTable value="#{visiteBean.listaRichiami()}"
                                                        var="result"
                                                        width="500px"
                                                        columnClasses="center"
                                                        rendered="#{visiteBean.render}"
                                                        >
                                            <f:facet name="header">
                                                <h:outputText value="Richiami"/>
                                            </f:facet>
                                            <rich:column sortBy="#{result.nomePaziente}">
                                                <f:facet name="header">
                                                    <h:outputText value="Nome"/>
                                                </f:facet>
                                                <h:outputText value="#{result.nomePaziente}"/>
                                            </rich:column>
                                            <rich:column sortBy="#{result.cognomePaziente}">
                                                <f:facet name="header">
                                                    <h:outputText value="Cognome"/>
                                                </f:facet>
                                                <h:outputText value="#{result.cognomePaziente}"/>
                                            </rich:column>
                                            <rich:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Data Visita"/>
                                                </f:facet>
                                                <h:outputText value="#{result.dataVisita}"/>
                                            </rich:column>
                                            <rich:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Tipo visita"/>
                                                </f:facet>
                                                <h:outputText value="#{result.tipoVisita}"/>
                                            </rich:column>
                                            <rich:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Urgenza"/>
                                                </f:facet>
                                                <h:graphicImage value="#{result.iconPath}"/>
                                            </rich:column>
                                            <rich:column>
                                                <f:facet name="header">
                                                    <h:outputText value="ID vista"/>
                                                </f:facet>
                                                <h:outputText value="#{result.idVisita}"/>
                                            </rich:column>
                                            <rich:column>
                                                <f:facet name="header">
                                                    <h:outputText value=""/>
                                                </f:facet>
                                                <a4j:commandButton action="#{visiteBean.preparaVisita(result.idVisita)}"
                                                                   value="visita"
                                                                   reRender="form"/>
                                            </rich:column>
                                        </rich:dataTable>
                                        <a4j:form id="visita" rendered="#{!visiteBean.render}">
                                            I campi con * sono obbligatori
                                            <table border="0" width="700px" cellspacing="10">
                                                <tbody>
                                                    <tr>
                                                        <td>*Paziente:</td>
                                                        <td>
                                                            <h:outputText value="#{visiteBean.nomePaziente} #{visiteBean.cognomePaziente}"/>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Categoria:</td>
                                                        <td><h:outputText value="#{visiteBean.tipoVisita}"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td>Medico curante:</td>
                                                        <td><h:outputText value="#{loginBean.nome} #{loginBean.cognome}"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td>*Tipologia visita:</td>
                                                        <td>
                                                            <rich:comboBox value="#{visiteBean.tipologia}"
                                                                           suggestionValues="#{visiteBean.richiamo}" 
                                                                           directInputSuggestions="true" 
                                                                           defaultLabel="Enter some value"
                                                                           enableManualInput="false"
                                                                           disabled="#{visiteBean.renderSuccess}"
                                                                           rendered="#{visiteBean.tipoVisita!='Vaccinazione'}"
                                                                           >
                                                                <a4j:support event="onlistclose" action="#{visiteBean.setData()}" reRender="data"/>
                                                            </rich:comboBox>
                                                            <h:outputText value="Puntura" rendered="#{ visiteBean.tipoVisita=='Vaccinazione'}"/>
                                                            <br>
                                                            <h:outputText styleClass="error" value="selezionare una tipologia" rendered="#{visiteBean.renderTipologiaError}"/>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>*Descrizione:</td>
                                                        <td> 
                                                            <h:inputTextarea id="descrizione" rows="3" cols="50" value="#{visiteBean.descrizione}" disabled="#{visiteBean.renderSuccess}" rendered="#{ visiteBean.tipoVisita!='Vaccinazione'}"/>
                                                            <h:outputText value="#{visiteBean.descrizione}" rendered="#{ visiteBean.tipoVisita=='Vaccinazione'}"/>
                                                            <br>
                                                            <h:outputText styleClass="error" value="descrizione troppo lunga" rendered="#{visiteBean.renderDescrizioneError_lunga}"/>
                                                            <h:outputText styleClass="error" value="inserire una descrizione" rendered="#{visiteBean.renderDescrizioneError_corta}"/>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>*Prossima visita:</td>
                                                        <td>
                                                            <rich:calendar id="data"
                                                                           value="#{visiteBean.data}"
                                                                           datePattern="dd/MM/yyyy HH:mm"
                                                                           enableManualInput="false"
                                                                           cellWidth="24px"
                                                                           cellHeight="22px"
                                                                           style="width:200px"
                                                                           disabled="#{visiteBean.renderSuccess}"
                                                                           rendered="#{visiteBean.tipoVisita!='Vaccinazione'}"
                                                                           />
                                                            <h:outputText value="Non sono previste ulteriori visite" rendered="#{visiteBean.tipoVisita=='Vaccinazione'}"/>
                                                            <h:outputText styleClass="error" value="inserire una data valida" rendered="#{visiteBean.renderCalendarError}"/>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                            <a4j:commandButton type="submit" value="Inserisci dati visita" action="#{visiteBean.effettuaVisita()}" reRender="form" rendered="#{!visiteBean.renderSuccess}"/>
                                            <h3><h:outputText value="  Visita registrata con successo" rendered="#{visiteBean.renderSuccess}"/></h3>                                            
                                            <h:outputText value="  Visita non registrata, provi a ricontrollare i campi inseriti" rendered="#{visiteBean.renderUnsuccess}"/>
                                        </a4j:form>
                                    </h:form>
                                </div>
                            </div>                           
                        </div>
                        <!-- end #content -->
                        <div id="sidebar">
                            <ul>
                                <li>
                                    <jsp:include page="../subviews/language_chooser.jsp"/>
                                </li>
                                <li>
                                    <jsp:include page="../subviews/side_reserved_menu.jsp"/>
                                </li>
                            </ul>
                        </div>
                        <!-- end #sidebar -->
                        <div style="clear: both;">&nbsp;</div>
                    </div>
                </div>
                <!-- end #page -->
                <div id="footer-bgcontent">
                    <div id="footer">
                        <p>Copyright &copy; 2011 <a href="#">Mamesoft</a>
                            Progetto Programmazione per il web A.A.2011/2012</p>
                    </div>
                </div>
                <!-- end #footer -->
            </div>
        </body>
    </html>
</f:view>